using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace 修为尽失.辅助
{
    public class NetHelper
    {
        public static IPAddress GetInternalIP()
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface adapter in nics)
            {
                foreach (var uni in adapter.GetIPProperties().UnicastAddresses)
                { 
                    if (uni.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        return uni.Address;
                    }
                }
            }
            return null;
        }

        public static bool CanIPReply(string ip,int timeout=1000)
        {
            var pingSender = new Ping(); 
            var reply = pingSender.Send(ip,timeout); 
            return reply != null && reply.Status == IPStatus.Success;
        }
    }
   
}